package com.xxxx.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created By ShaoXikai on 2022/7/21
 */
@Component
@Aspect
public class OnceAdvice {

    // 定义切点
    @Pointcut("execution(* com.xxxx.dao.BookDao.*d*(..))")
    private void pt() {
    }

    @Before("pt()")
    public void before() {
        System.out.println("开始执行！");
    }

    @After("pt()")
    public void after() {
        System.out.println("执行完毕！");
    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) {
        System.out.println("============执行开始============");
        // Long startTime = System.currentTimeMillis();
        // for (int i = 0; i < 10000; i++) {
        //调用原始操作
        try {
            pjp.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
            throw new RuntimeException("执行错误");
        }
        System.out.println("============执行结束============");
        // }
        // Long endTime = System.currentTimeMillis();
        // long totalTime = endTime - startTime;
        // System.out.println("执行万次消耗时间：" + totalTime + "ms");
        return null;
    }
}
